<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1">
	<meta name="description" content="A fully featured admin theme which can be used to build CRM, CMS, etc.">
	<meta name="author" content="Coderthemes">
	
	<!-- jQuery  -->
	<script src="/js/jquery3/jquery.min.js"></script>
	<th:block th:include="include :: footer" />
	<script type="text/html" id="index">
		{{d.LAY_TABLE_INDEX+1}}
	</script>


	<!-- layui  -->
	<link rel="stylesheet" href="/js/layuiadmin-1.2.1/layui2.7.6/css/layui.css" media="all" />
	<script type="text/javascript" src="/js/layuiadmin-1.2.1/layui2.7.6/layui.js"></script>
</head>

<body>
	<form class="layui-form" id="id_form" method="post" action="">
		
		<table id="id_table_fenxiang"></table>
		<script th:inline="javascript">
		ali1688EcpApiUrl = [[${ali1688EcpApiUrl}]],
		layui.use(['table', 'dropdown'], function(){
			var dom = $('#id_table_fenxiang');
			layui.table.render({
				elem: '#' + dom.attr('id'),
				limit: 9999,
				id: dom.attr('id'),
				rowDrag: {
					done: function(obj) {}
				},
				totalRow: true,
				cols: [ [
					{ field: 'index',title: '序号',type:'numbers'},
					{field: 'paymentTime', title: '订单创建日期', align:'center',sort: true,},
						{field: 'updateTime', title: '执行时间', align:'center',sort: true,},
						{field: 'type', title: '状态', align:'center',sort: true,},
						{field: 'message', title: '失败原因', align:'center',sort: true,},
						{field: 'ope', title: '操作', align:'center', width:380, templet:function(data){
							var returnStr = '<a href="#" class="layui-btn layui-btn-sm layui-btn-normal" onclick="doPrintGoods(\'' + data.paymentTime + '\',\'' + data.updateTime + '\')">重新执行</a>';
							return returnStr;
						}}
				] ],
				data: $.parseJSON(JSON.stringify([[${dto}]])),
				done: function(){
				}
			});
		})
		</script>
	</form>
	<script>
	$(function () {
		layui.use(['laydate','form','layer'], function(){
			var form = layui.form;

			// 表单提交，共用同一个
			form.on('submit(formSubmit)', function(data){
				var checkStatus = layui.table.checkStatus('id_table_fenxiang');
				var rows = checkStatus.data;
				if (rows.length <= 0) {
					layer.msg('请选择至少一条数据');
					return false;
				}
				//window.parent.tableOfShowingPerson.addRow(rows[0]);
				window.parent.tableOfShowingPerson.addRows(rows);
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
				return false;
			});
		});
	});
	
	function doPrintGoods(paymentTime,updateTime) {
		//填写备注
		layer.open({
			type: 1,
			area: ['400px', '200px'],
			title: '执行日期',
			shadeClose:true,
			offset: '5%',
			content: `<div><label class="layui-form-label"><i style="color:red">*&nbsp;&nbsp;</i>执行时间:</label><div class="layui-inline">
						  <input type="text" class="layui-input executionTime" id="executionTime" value=${paymentTime}>
						</div></div>`,
			btn: ['确认', '取消'],
			yes: function (index, layero) {
				var executionTime = $('.executionTime').val()
				if (!executionTime) return layer.msg("请选择执行时间!");
				var nowTime = get_now_date();
				if (executionTime >= nowTime) return layer.msg("选择的订单日期应该小于当前日期!!");
				layer.open({
					offset: 'rb',
					title: '系统通知',
					area: ['350px', '85px'],
					shade: 0,
					type: 1,
					content: `<div class="toast toast--green">
							    <p class="toast__type">已发送至后台处理!</p>
							  </div>`,
					time: 10000,//弹窗时长
					icon: 1,
					anim: 2
				});
				showloadings(true);
				//更新订单操作
				$.post(ali1688EcpApiUrl+'/api/outer/amazonShop/updateAllByHand',{paymentTime:executionTime},function(result){
					if (result.code == 0){
						setTimeout(function(){
							layer.msg("操作成功,等待15分钟后刷新订单!");
							showloadings(false);
						}, 1000);
					} else {
						setTimeout(function(){
							layer.msg("短时间内不允许操作!");
							showloadings(false);
						}, 1000);
						showloadings(false);
					}
				});
			}
		});
		layui.laydate.render({
			elem: '#executionTime' //指定元素
		});

	}
	function get_now_date(){
		var timestamp = Date.parse(new Date());
		var date = new Date(timestamp);
		//获取年份
		var Y =date.getFullYear();
		//获取月份
		var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
		//获取当日日期
		var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();

		return Y+'-'+M+'-'+D;
	}

	</script>
</body>
</html>